package com.qf.smsplatform.search.mq;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.model.StandardReport;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.search.service.SearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: LeeRui
 * 2021/2/2 下午 7:44
 * 监听网关模块更新报告消息队列，更新ES中指定doc_id的文档信息
 **/
@Component
public class UpdateReportListener {

    @Autowired
    private SearchService searchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT)
    public void reportConsumer(StandardReport standardReport, Channel channel, Message message) throws IOException {
        //执行ES中报告更新
        searchService.updateReport(standardReport);
        //手动ACK
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
